< previous page page_429 next page >

Page 429
0429-01.jpg
Figure 19.3
To place a picture in a form, PictureBox,
or Image control at designtime, use the
Load Picture dialog box. Pictures can also
be loaded during program execution.
While your program is running, pictures can be moved from one control to another by assigning the Picture property or can be loaded from a file type listed in Table 19.1. To set the Picture property from a file, use the LoadPicture method. The following code sample shows you how to load pictures on a form, Image control, and PictureBox control at runtime:
'Examples of Loading pictures
Form1.Picture = LoadPicture("C:\MYPIC.BMP")
Image1.Picture = LoadPicture("D:\PAMELA.JPG")
Picture1.Picture = image1.PicturePicture1.Picture = LoadPicture("")
Note that passing an empty string to the LoadPicture function clears the current picture. Visual Basic also has a SavePicture statement, which is used to save pictures from the Picture property to a disk file. However, some limitations do exist on the file formats that can be saved. Although the LoadPicture function works with GIF or JPG files, the SavePicture function does not save in those formats. Pictures saved from the Image control are always saved in BMP format. For a complete list of restrictions, look up SavePicture in the Help index.
Loading Pictures on a Form
A picture loaded on a form has a relatively fixed behavior, much like background wallpaper in Windows. The picture starts in the upper-left corner and is not sized or scaled in any way to match the size of the form. If the picture is smaller than the form, space is left below and to the right of the picture. If the picture is larger than the form, the entire picture is still loaded, but only part of it is visible. As the form is resized, the amount of the picture shown changes.
With the exception of the Label and Shape controls, the picture does not show through the background of the controls on the form. The Label and Shape controls allow the picture to show through if the BackStyle property of the control is set to Transparent. Figure 19.4 illustrates controls placed on a form containing a picture. Note how the background picture shows through the Label control just above the text box.
tip.gif
You cannot resize a picture that is placed directly on a form. If you want the picture to be a different size, you need to resize the original graphic file using a graphics utility.

The key advantage to placing your picture directly on the form is that this method uses fewer system resources than placing the picture in a Picture or Image control. Another benefit of placing the picture on the form is that you can use drawing methods to annotate the picture.

 
< previous page page_429 next page >